/*
    Copyright 2009 Michael Ogawa

    This file is part of OpenWordle.

    OpenWordle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenWordle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenWordle.  If not, see <http://www.gnu.org/licenses/>.
*/

import openwordle.*;
import openwordle.util.*;
import openwordle.parsers.*;
import java.io.*;

final String FILENAME = "input.txt";
final color BACKGROUND = color(0);
final String FONT_NAME = "SansSerif";

WordWeightParser parser;
WordleLayout layout;
java.util.List words;
Iterator itr;
PFont font;
int startTime;

void setup()
{
  size( 1024, 768 );
  smooth();
  
  parser = new WordWeightParser();
  
  InputStream in = createInput( FILENAME );
  try
  {
    parser.load( in );
  }
  catch( Exception ex )
  {
    ex.printStackTrace();
  }
  
  words = parser.getWords();
  Collections.sort( words );
  itr = words.iterator();
  
  layout = new WordleLayout( this, BACKGROUND );
  layout.setAngleType( layout.ANYWAY );
  
  font = createFont( FONT_NAME, 48 );
  background( BACKGROUND );
  startTime = millis();
}

void draw()
{
  if( itr.hasNext() )
  {
    Word word = (Word)itr.next();
    println( word.toString() );
    int fontSize = (int)map( word.weight, parser.getMinWeight(), parser.getMaxWeight(), 16, 100 );
    word.font = font;
    word.fontSize = fontSize;
    layout.doWordleLayout( word );
    fill( ColorStuff.BlueIce[ (int)random(ColorStuff.BlueIce.length) ] );
    layout.paintWord( word );
  }
  else
  {
    int endTime = millis();
    println( "Done: " + (endTime - startTime) + " msec" );
    noLoop();
  }
}


